const { UI_Layer } = require("../../config/ui_def");

cc.Class({
    extends: cc.Component,

    properties: {
    },
    initPage(){
        this.k_c = {
            1004 : 200,
            1002 : -200,
            1001 : 200,
            1003 : -200
        } 
        this.k_n = {
            1004 : 'max',
            1002 : 'sammy',
            1001 : 'volt',
            1003 : 'lucy'
        }
        this.team_ani = []
    },
    updatePage(){
        let team = he.local.getJson("team",'user')
        let have = []
        for(let i = 0; i < team.length;i++){
            if(team[i].order > 0){
                have.push(team[i].id)
            }
        }
        for(let key in this.k_c){
            let k_n = this.node.getChildByName(key) 
            k_n.y = this.k_c[key]
            let k_sprite = k_n.getComponent(cc.Sprite)
            if(have.indexOf(parseInt(key)) < 0){
                k_sprite.spriteFrame = he.load.get('goPass',cc.SpriteAtlas,'plist').getSpriteFrame(this.k_n[key]+'_hide')
            }else{
                k_sprite.spriteFrame = he.load.get('goPass',cc.SpriteAtlas,'plist').getSpriteFrame(this.k_n[key]+'_show')
            }
            let node_ani = cc.tween(k_n).to(1.5,{ y : 0}).start()
            this.team_ani.push(node_ani)
        }
        let ani = cc.tween(this.node).delay(2).call( res => {
            gg.uiManager.addPage(UI_Layer.Load, {
                name: "LoadCover",
                in: true,
                scene: 'Playground'
            })
        }).start()
        this.team_ani.push(ani)
        he.voice.stopMusic()
        he.voice.playEffect('go_pass','voice')
    },
    closeUI(){
        for(let i = this.team_ani.length - 1; i >= 0 ; i--){
            this.team_ani[i].stop()
            this.team_ani.splice(i,1)
        }
    }
});
